package com.acwing.partition44;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/27 19:29
 */
public class AC4380合并石子_双指针_前缀和 {

    private static final int N = 100010;
    private static int[] s1 = new int[N], s2 = new int[N];
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        m = Integer.parseInt(ss[1]);
        ss = reader.readLine().split(" ");
        for (int i = 1; i <= n; i++) s1[i] += s1[i - 1] + Integer.parseInt(ss[i - 1]);
        ss = reader.readLine().split(" ");
        for (int i = 1; i <= m; i++) s2[i] += s2[i - 1] + Integer.parseInt(ss[i - 1]);
        int ans = 0;
        for (int i = 1, j = 1; i <= n; i++) {
            while (s2[j] < s1[i]) j++;
            if (s1[i] == s2[j]) ans++;
        }
        writer.write(ans + "\n");
        writer.flush();
    }
}
